<?php $this->load->view('common/header'); ?>
<?php echo vip_css_url('style'); ?>
<body>
<?php $this->load->view('common/user_center'); ?>
<div class="main_box">
    <?php $this->load->view('common/menu'); ?>
    <div class="right_box f_r">
        <div class="title">
            <span class="f_l">产品管理</span>
            <span class="f_r">
            	excel产品管理模版
                <a href="<?php echo $excel_template; ?>" download="excel_template.xlsx">【点击下载】</a>
                <a href="javascript:;" class="blue">
                    <input type="file" id="uploadFile" name="uploadFile"
                           onchange="uploadFile(this,<?php echo $user['user_id']; ?>)">
                    批量导入</a>
                <a href="<?php echo site_url(V_URL . 'product/add') ?>" class="red">新增产品</a>
            </span>
        </div>
        <div class="table_box">
            <table>
                <tr>
                    <th>分类</th>
                    <th>产品名称</th>
                    <th class="w140">规格</th>
                    <th class="w140">单价</th>
                    <th>制作工艺</th>
                    <th>工艺图</th>
                    <th>料号</th>
                    <th class="operating">操作</th>
                </tr>
                <?php if ($goods) {
                    foreach ($goods as $key => $val) { ?>
                        <tr>
                            <td><?php echo $val['good_category']; ?></td>
                            <td><?php echo $val['good_title']; ?></td>
                            <td class="w140"><?php echo $val['good_memo']; ?>m</td>
                            <td class="w140"><?php echo $val['good_price']; ?></td>
                            <td><?php echo $val['good_content']; ?></td>
                            <td>
                                <img src="<?php echo $val['good_cover']; ?>" alt="" width="50px">
                            </td>
                            <td><?php echo $val['good_part_number']; ?></td>
                            <td class="operating">
                                <a class="red" href="<?php echo site_url(V_URL . 'product/edit/' . $val['good_id']); ?>"
                                   title="编辑">编辑</a>
                            </td>
                        </tr>
                    <?php } ?>
                <?php } ?>
            </table>
            <div class="demo">
                <?php if ($pagination) { ?>
                    <ul class="pagination pagination_type2 pagination_type3">
                        <?php echo $pagination; ?>
                    </ul>
                <?php } ?>
            </div>

        </div>
    </div>
</div>
<!--]] user -->
<!-- coypright [[-->
<script>
    var url = baseurl + 'index.php/vip/upload/upload_excel';

    function uploadFile(obj, type) {
        $.ajaxFileUpload({
            url: url,
            secureuri: false,// 一般设置为false
            fileElementId: "uploadFile",// 文件上传表单的id <input type="file" id="fileUpload" name="file" />
            dataType: 'json',// 返回值类型 一般设置为json
            data: {'type': type},
            success: function (data) // 服务器成功响应处理函数
            {
                if (data.status == 200) {
                    layer.msg('上传成功', {
                        time: 1000, //1s后自动关闭
                        shade: 0.1
                    }, function () {
                        window.location.href = window.location.href;
                    });
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function (data)// 服务器响应失败处理函数
            {
                layer.msg('上传成功', {
                    time: 1000, //1s后自动关闭
                    shade: 0.1
                }, function () {
                    window.location.href = window.location.href;
                });
            }
        });
        return false;
    }

    $(".edit").click(function () {
        var good_id = $(this).attr('val');
        var URL = "<?php echo site_url(V_URL . 'product/del_pro');?>";
        layer.confirm('确定删除该产品吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "post",
                url: URL,
                dataType: 'json',
                data: {
                    'good_id': good_id,
                    'csrf_test_name': ci_csrf_token()
                },
                success: function (data) {
                    if (data.status == 200) {
                        layer.msg('删除成功', {
                            time: 1000, //1s后自动关闭
                            shade: 0.1
                        }, function () {
                            window.location.href = "<?php echo site_url(V_URL . 'product/index');?>";
                        });
                    } else {
                        layer.msg(data.msg);
                        return false;
                    }

                }
            });
        });
    });
</script>
<?php $this->load->view('common/footer'); ?>
<!--]] coypright -->
</body>
</html>
